/*
 * SipDialog.h
 *
 *  Created on: Dec 6, 2011
 *      Author: shaohong
 */

#ifndef SIPDIALOG_H_
#define SIPDIALOG_H_

#include <string>

#include "SipMessage.h"

using namespace std;

namespace nmps {

enum DialogState {NEW, EARLY, ESTABLISHED};

class SipServer;
/**
 * A sip dialog maintains the state of a SIP dialog
 * such as the dialog state: initial, early, established.
 * Call-id, pending transaction, etc.
 */
class SipDialog {
public:
	SipDialog(string callID);
	virtual ~SipDialog();

	string getCallID();

	void handleRequest(SipRequest * sipRequest);
	void handleResponse(SipResponse *sipResponse);
	DialogState state;

	// send out the SIP response
	static void sendResponse(SipResponse * sipResponse);

	void setSipServer(SipServer * sipServer);
	SipServer * getSipServer();

//private:
	string callID;
	string localUriAndParams; // the from header when we send message out
	string peerUriAndParams; // the to header when we send message out

	SipServer * sipServer;

	int peerChannelNumber;	// the channelNumber peer is currently listening to
	string peerMediaIp;	// this the IP indicated by the peer's SDP
	unsigned int peerMediaPort;  // this is the port indicated by the peer's SDP

private:
    void handleInvite(SipRequest *sipRequest);
	void handleBYE(SipRequest * sipRequest);
	void handleINFO(SipRequest * sipRequest);

};

} /* namespace nmps */
#endif /* SIPDIALOG_H_ */
